Health = class()
Health.fixedHealth = 20

function Health:init()
    self.img = readImage("Project:blood volume")
    self.fh = self.img:copy(1,10,9,9)
    self.nh = self.img:copy(37,10,9,9)
    self.nhh = self.img:copy(46,10,9,9)
    self.img = nil
    self.fixedHealth = Health.fixedHealth --固定血条
    self.health = self.fixedHealth --当前血量
    self.x = selector.left
    self.y = Selector.width + 10
end

function Health:render()
    pushMatrix()
    pushStyle()
    noSmooth()
    spriteMode(CORNER)
    tint(255, 255, 255, 255)
    local health = math.ceil(self.health)
    for i = 0,self.fixedHealth/2 - 1 do
        sprite(self.fh,self.x + 27*i,self.y,30,30)
    end
    for j = 0,health / 2 - 1 do
        sprite(self.nh,self.x + 27*j,self.y,30,30)
        if health % 2 == 1 then
            sprite(self.nhh,self.x + 27 * math.floor(health / 2),self.y,30,30)
        end
    end
    popStyle()
    popMatrix()
end

Oxygen = class()

function Oxygen:init()
    self.o2 = readImage("Project:oxygen")
    self.o2b = readImage("Project:oxygen bo")
    self.canDo = false
    self.o2t = 10
end

function Oxygen:render()
    for k = 1,self.o2t do
        sprite(self.o2,5+27*k,HEIGHT/2-30,30,30)
    end
    if player:isInWater() then
        if math.floor(ElapsedTime) % 3 == 1 and self.canDo == false then
            self.o2t = self.o2t -1
            self.canDo = true
        elseif math.floor(ElapsedTime) % 3 ~= 1 then
            self.canDo = false
        end
        if math.floor(ElapsedTime*10)/10%3 == 1 then
            sprite(self.o2b,5+27*(self.o2t+1),HEIGHT/2-30,30,30)
        end
    end
end

